package com.ecy.quadratic.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ecy.quadratic.R;
import com.ecy.quadratic.beans.CommunitySpecialArea;

import java.util.List;

public class CommunitySpecialAreaAdapter extends BaseAdapter {

    private List<CommunitySpecialArea> mComicList;
    private Activity mContext;

    public CommunitySpecialAreaAdapter(Activity context, List<CommunitySpecialArea> comicList) {
        mContext = context;
        mComicList = comicList;
    }

    @Override
    public int getCount() {
        return mComicList == null ? 0 : mComicList.size();
    }

    @Override
    public CommunitySpecialArea getItem(int position) {
        if (mComicList != null) {
            return mComicList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.fragment_community_specialarea_item, null);
            viewHolder = new ViewHolder();
            viewHolder.comicTitleTV = (TextView) convertView.findViewById(R.id.community_specialarea_title_tv);
            viewHolder.comicDescribeTV = (TextView) convertView.findViewById(R.id.community_specialarea_describe_tv);
            viewHolder.comicReaderNumTV = (TextView) convertView.findViewById(R.id.community_special_membernum_tv);
            viewHolder.comicCoverIV = (ImageView) convertView.findViewById(R.id.community_specialarea_cover_iv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CommunitySpecialArea communityArea = getItem(position);
        viewHolder.comicTitleTV.setText(communityArea.getTitle());
        viewHolder.comicDescribeTV.setText(communityArea.getDes());
        convertView.setBackgroundColor(communityArea.getBackgroundColor());
        Glide.with(mContext).load(communityArea.getImgResId() != 0 ? communityArea.getImgResId() : communityArea.getImg()).into(viewHolder.comicCoverIV);
        return convertView;
    }

    public class ViewHolder {
        public TextView comicTitleTV;
        public TextView comicDescribeTV;
        public TextView comicReaderNumTV;
        public ImageView comicCoverIV;
    }

}
